@extends('layouts.seller')

@section('title', '宝贝管理')

@section('content')
    <ul class="breadcrumb">
        <li class="breadcrumb-item">卖家中心</li>
        <li class="breadcrumb-item">宝贝管理</li>
        <li class="breadcrumb-item active">{{$status=='onSale' ? '出售中的宝贝' : '仓储中的宝贝'}}</li>
    </ul>
    <div class="list-div">
        <form method="post" id="listForm" autocomplete="off">
            {{form_verify_field()}}
            <input type="hidden" id="eventType" name="eventType" value="delete">
            <table cellpadding="0" cellspacing="0" border="0" width="100%" class="listtable">
                <thead>
                <tr>
                    <th width="30" class="first"><input title="" type="checkbox" class="checkmark" data-action="checkall"></th>
                    <th width="80">图片</th>
                    <th>商品名称</th>
                    <th>价格</th>
                    <th>销量</th>
                    <th>上架时间</th>
                    <th>状态</th>
                    <th width="80" class="align-center">操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach ($items as $item)
                    <tr id="row_{{$item['itemid']}}">
                        <td class="first"><input title="" type="checkbox" class="checkmark" name="items[]" value="{{$item['itemid']}}"></td>
                        <td>
                            <div class="bg-cover" style="width: 80px; height: 80px; background-image: url({{image_url($item['thumb'])}})"></div>
                        </td>
                        <td>
                            <h3 style="font-size: 12px;"><a href="{{item_url($item['itemid'])}}" target="_blank">{{$item['title']}}</a></h3>
                            <p style="margin-top: 5px; color: #888; font-size: 11px;">{{$item['subtitle']}}</p>
                        </td>
                        <td>{{$item['price']}}</td>
                        <td>{{$item['sold']}}</td>
                        <td>{{@date('Y-m-d H:i', $item['created_at'])}}</td>
                        <td>
                            @if ($item['on_sale'])
                                出售中
                            @else
                                已下架
                            @endif
                        </td>
                        <td class="align-center">
                            <a href="{{url('/seller/item/publish?catid='.$item['catid'].'&itemid='.$item['itemid'])}}">编辑宝贝</a>
                        </td>
                    </tr>
                @endforeach
                </tbody>
                <tfoot>
                <tr>
                    <td colspan="20" class="first">
                        <div class="float-right">{!! $pagination !!}</div>
                        <div class="btn-group-sm">
                            <label class="form-check-label"><input type="checkbox" class="checkmark" data-action="checkall"> 全选</label>
                            <button type="button" class="btn btn-default btn-action" id="delete" disabled="disabled">批量删除</button>
                            <button type="button" class="btn btn-default btn-action" id="onSale" disabled="disabled">批量上架</button>
                            <button type="button" class="btn btn-default btn-action" id="offSale" disabled="disabled">批量下架</button>
                        </div>
                    </td>
                </tr>
                </tfoot>
            </table>
        </form>
    </div>
    <script type="text/javascript">
        $(function () {
            function submitForm() {
                $("#listForm").ajaxSubmit({
                    beforeSend:DSXUI.showSpinner,
                    success:function (response) {
                        setTimeout(function () {
                            DSXUI.hideSpinner();
                            DSXUtil.reFresh();
                        }, 500);
                    }
                });
            }
            $(document).on('click', function () {
                if ($(".checkmark:checked").length > 0 ) {
                    $(".btn-action").enable();
                } else {
                    $(".btn-action").disable();
                }
            });
            $("#delete").on('click', function () {
                DSXUI.showConfirm('你确认要删除所选宝贝吗?', function () {
                    $("#listForm").ajaxSubmit({
                        url:'/seller/item/delete',
                        beforeSend:DSXUI.showSpinner,
                        success:function (response) {
                            setTimeout(function () {
                                DSXUI.hideSpinner();
                                DSXUtil.reFresh();
                            }, 500);
                        }
                    });
                });
            });

            function toggleSale(on_sale)
            {
                $("#listForm").ajaxSubmit({
                    url:'/seller/item/togglesale?on_sale='+on_sale,
                    beforeSend:DSXUI.showSpinner,
                    success:function (response) {
                        setTimeout(function () {
                            DSXUI.hideSpinner();
                            DSXUtil.reFresh();
                        }, 500);
                    }
                });
            }
            $("#onSale").on('click', function () {
                toggleSale(1);
            });
            $("#offSale").on('click', function () {
                toggleSale(0);
            });
        });
    </script>
@stop
